package com.topsun.posclient;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.topsun.posclient.finance.OpenPaymentAction;
import com.topsun.posclient.repository.OpenCheckRepositoryAction;
import com.topsun.posclient.repository.OpenFinanceAction;
import com.topsun.posclient.repository.OpenInventoryCheckAction;
import com.topsun.posclient.repository.OpenTuneRepositoryAction;
import com.topsun.posclient.repository.OpenTuneStoreAction;
import com.topsun.posclient.sales.OpenPartSaleAction;
import com.topsun.posclient.system.SyncDataAction;

/**
 * An action bar advisor is responsible for creating, adding, and disposing of
 * the actions added to a workbench window. Each window will be populated with
 * new actions.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private IWorkbenchAction openPartSaleAction;
	private IWorkbenchAction openPaymentAction;
	
	private IWorkbenchAction openCheckRepositoryAction;
	private IWorkbenchAction openInventoryCheckAction;
	private IWorkbenchAction openTuneRepositoryAction;
	private IWorkbenchAction openTuneStoreAction;
	
	private IWorkbenchAction openFinanceAction;
	
	private IWorkbenchAction syncDataAction;
	private IWorkbenchAction exitAction;
    private IWorkbenchAction aboutAction;

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	protected void makeActions(IWorkbenchWindow window) {
		
		syncDataAction = new SyncDataAction(window);
		syncDataAction.setText("同步用户数据");
		syncDataAction.setId("com.topsun.posclient.system.SyncDataAction");
        register(syncDataAction);
        
		exitAction = ActionFactory.QUIT.create(window);
		exitAction.setText("退出");
        register(exitAction);
        
        aboutAction = ActionFactory.ABOUT.create(window);
        aboutAction.setText("关于");
        register(aboutAction);
        
        openPartSaleAction = new OpenPartSaleAction(window);
        openPartSaleAction.setText("零售");
        openPartSaleAction.setId("com.topsun.posclient.sales.OpenPartSaleAction");
		register(openPartSaleAction);
		
		openPaymentAction = new OpenPaymentAction(window);
		openPaymentAction.setText("店铺缴款");
		openPaymentAction.setId("com.topsun.posclient.finance.OpenPaymentAction");
		register(openPaymentAction);
		
		openCheckRepositoryAction = new OpenCheckRepositoryAction(window);
		openCheckRepositoryAction.setText("库存盘点");
		openCheckRepositoryAction.setId("com.topsun.posclient.repository.OpenCheckRepositoryAction");
		register(openCheckRepositoryAction);
		
		openInventoryCheckAction = new OpenInventoryCheckAction(window);
		openInventoryCheckAction.setText("盘点核对");
		openInventoryCheckAction.setId("com.topsun.posclient.repository.OpenInventoryCheckAction");
		register(openInventoryCheckAction);
		
		openTuneRepositoryAction = new OpenTuneRepositoryAction(window);
		openTuneRepositoryAction.setText("仓调仓");
		openTuneRepositoryAction.setId("com.topsun.posclient.repository.OpenTuneRepositoryAction");
		register(openTuneRepositoryAction);
		
		openTuneStoreAction = new OpenTuneStoreAction(window);
		openTuneStoreAction.setText("店调店");
		openTuneStoreAction.setId("com.topsun.posclient.repository.OpenTuneStoreAction");
		register(openTuneStoreAction);
		
		openFinanceAction =new OpenFinanceAction(window);
		openFinanceAction.setText("结算方式");
		openFinanceAction.setId("com.topsun.posclient.repository.OpenFinanceAction");
		register(openFinanceAction);
	}

	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager newMenu1 = new MenuManager("销售", "com.topsun.posclient.finance.OpenBallotAction");
		newMenu1.add(openPartSaleAction);
		
		MenuManager newMenu2 = new MenuManager("财务管理", "com.topsun.posclient.finance.OpenBallotAction");
		newMenu2.add(openFinanceAction);
		newMenu2.add(openPaymentAction);
		
		MenuManager newMenu3 = new MenuManager("库存", "com.topsun.posclient.finance.OpenBallotAction");
		newMenu3.add(openCheckRepositoryAction);
		newMenu3.add(openInventoryCheckAction);
		newMenu3.add(openTuneRepositoryAction);
		newMenu3.add(openTuneStoreAction);
		
		MenuManager newMenu5 = new MenuManager("系统管理", "com.topsun.posclient.finance.OpenBallotAction");
		newMenu5.add(syncDataAction);
		newMenu5.add(exitAction);
		newMenu5.add(aboutAction);
		
		menuBar.add(newMenu1);
		menuBar.add(newMenu2);
		menuBar.add(newMenu3);
		menuBar.add(newMenu5);
	}

}
